﻿<%@ WebHandler Language="C#" Class="UploadHandler" %>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Text.RegularExpressions;
using Dln.Common.Helper;
using Dln.Model;

/// <summary>
/// UploadHandler 的摘要说明
/// </summary>
public class UploadHandler : HandlerBase
{

    /// <summary>
    /// 上传话题图片
    /// </summary>
    public void UploadTopicImage()
    {
        try
        {
            this.Context.Response.ContentType = "text/plain";
            var file = Context.Request.Files[0];
            string type = RequestString("type");
            var dirPath = "";
            var savePath = "";

            if (!string.IsNullOrEmpty(type))
            {

                //dirPath = "D:/沭阳中医院工作系统/WAP/Images/TopicImg";
                if (type == "TopicImage")
                {
                    dirPath = "E:/Dln任务管理（微信）/Dln/Dln/WapTest/Images/TopicImg/";
                    savePath = "http://localhost:5737/images/TopicImg/";
                }
                else if (type == "problemSolveImage")
                {
                    dirPath = "E:/Dln任务管理（微信）/Dln/Dln/WapTest/Images/problemSolveImage/";
                    savePath = "http://localhost:5737/images/problemSolveImage/";
                }
                else
                {
                    dirPath = "E:/Dln任务管理（微信）/Dln/Dln/WapTest/Images/problemImage/";
                    savePath = "http://localhost:5737/images/problemImage/";
                }
            }

            var sb = new StringBuilder();
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }
            if (file != null)
            {
                try
                {
                    var picName = Guid.NewGuid().ToString();
                    file.SaveAs(dirPath + picName + ".jpg");
                    sb.Append("{'success':true,'msg':'" + savePath + picName + ".jpg" + "'}");
                }
                catch (Exception ex)
                {
                    sb.Append("{'success':false,'msg':'" + "图片上传失败，请重新上传" + "'}");
                }
            }
            Context.Response.Write(sb.ToString().Replace("'", "\""));
        }
        catch (Exception ex)
        {
        }


    }



    /// <summary>
    /// 上传问题反馈图片
    /// </summary>
    public void UploadSolveImage()
    {
        //try
        //{
        //    this.Context.Response.ContentType = "text/plain";
        //    var file = Context.Request.Files[0];
        //    int Id = Convert.ToInt32(RequestString("Id"));
        //    var dirPath = "";
        //    var savePath = "";

        //    dirPath = "D:/沭阳中医院工作系统/WAP/Images/problemSolveImage/";

        //    //dirPath = "E:/Dln任务管理（微信）/Dln/Dln/WapTest/Images/problemSolveImage/";
        //    //savePath = "http://localhost:5737/images/problemSolveImage/";
        //    savePath = "http://www.healthyperson.cn/images/problemSolveImage/";
        //    var sb = new StringBuilder();

        //    var orderModel = SqlHelper.ContextDlnOnline.From<dt_order>().Where(d => d.id == Id).ToFirst();
        //    if (orderModel == null)
        //    {
        //        sb.Append("{'success':false,'msg':'" + " 未找到该报修信息，请联系信息科" + "'}");
        //        Context.Response.Write(sb.ToString().Replace("'", "\""));
        //        Context.Response.End();
        //    }
        //    if (!Directory.Exists(dirPath))
        //    {
        //        Directory.CreateDirectory(dirPath);
        //    }
        //    if (file != null && !string.IsNullOrEmpty(file.FileName))
        //    {
        //        try
        //        {
        //            var picName = Guid.NewGuid().ToString();
        //            file.SaveAs(dirPath + picName + ".jpg");

        //            orderModel.solveImg = "/images/problemSolveImage/" + picName + ".jpg";
        //            var count = SqlHelper.ContextDlnOnline.Update<dt_order>(orderModel);

        //            sb.Append("{'success':true,'msg':'" + savePath + picName + ".jpg" + "'}");
        //        }
        //        catch (Exception ex)
        //        {
        //            sb.Append("{'success':false,'msg':'" + "图片上传失败，请重新上传" + "'}");
        //        }
        //    }
        //    else
        //    {
        //            sb.Append("{'success':false,'msg':'" + "请选择要上传的图片！" + "'}");
        //    }



        //    Context.Response.Write(sb.ToString().Replace("'", "\""));
        //}
        //catch (Exception ex)
        //{
        //}


    }
}
